package com.hs.kfk.boot;

import com.alibaba.fastjson2.JSON;
import com.hs.kfk.serializer.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: kafka整合SpringBoot，消息生产者
 * @Author 胡尚
 * @Date: 2024/8/8 17:03
 */
@RestController()
public class BootProducer {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/send")
    public void sendMessage(){
        User user = new User(1L, "hushang", 24);
        String message = JSON.toJSON(user).toString();
        kafkaTemplate.send("disTopic", "key", message);
    }
}
